package com.springboot_gradrecruit.controller;

import com.springboot_gradrecruit.common.R;
import com.springboot_gradrecruit.model.entity.Send;
import com.springboot_gradrecruit.model.vo.chart.CityAverageSalary;
import com.springboot_gradrecruit.model.vo.chart.IndustryJobSpread;
import com.springboot_gradrecruit.model.vo.chart.SendRecordChange;
import com.springboot_gradrecruit.model.vo.chart.SendRecordSpread;
import com.springboot_gradrecruit.service.JobService;
import com.springboot_gradrecruit.service.SendService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author zr
 */
@Tag(name = "图表相关接口")
@RestController
@RequestMapping("/chart")
public class ChartController {

    @Resource
    private JobService jobService;

    @Resource
    private SendService sendService;


    @Operation(summary = "管理员-查询行业岗位分布数量")
    @PostMapping("/querySpreadJobCount")
    public R<IndustryJobSpread> querySpreadJobCount(){
        IndustryJobSpread industryJobSpread=jobService.querySpreadJobCount();
        return R.success(industryJobSpread, "查询成功");
    }

    @Operation(summary = "管理员-查询热门城市平均薪资")
    @PostMapping("/queryHotCityAverageSalary")
    public R<CityAverageSalary> queryHotCityAverageSalary(){
        CityAverageSalary cityAverageSalary=jobService.queryHotCityAverageSalary();
        return R.success(cityAverageSalary, "查询成功");
    }


    @Operation(summary = "企业-查询近七周投递学历占比情况")
    @PostMapping("/querySendRecordSpread")
    public R<SendRecordSpread> querySendRecordSpread(Long enterpriseId){
        //1. 参数校验
        if(enterpriseId==null){
            throw new RuntimeException("参数为空");
        }
        //2. 调用service完成查询
        //2-1 查询近期（七周）的投递记录，按照时间，根据企业ID
        List<Send> sendList =sendService.queryRecentSendRecordsGroupByTime(enterpriseId);
        //2-2 根据投递记录，查询投递记录学历分布情况
        SendRecordSpread sendRecordSpread=sendService.querySendRecordSpread(sendList);
        if(sendRecordSpread==null){
            return R.error(null,"查询失败");
        }
        return R.success(sendRecordSpread, "查询成功");
    }

    @Operation(summary = "企业-查询近七周投递变化情况")
    @PostMapping("/querySendRecordChange")
    public R<SendRecordChange> querySendRecordChange(Long enterpriseId){
        //1. 参数校验
        if(enterpriseId==null){
            throw new RuntimeException("参数为空");
        }
        //2. 调用service完成查询
        //2-1 查询近期（七周）的投递记录，按照时间，根据企业ID
        List<Send> sendList =sendService.queryRecentSendRecordsGroupByTime(enterpriseId);
        //2-2 根据投递记录，查询每周投递数据
        SendRecordChange sendRecordChange=sendService.querySendRecordChange(sendList);
        if(sendRecordChange==null){
            return R.error(null,"查询失败");
        }
        return R.success(sendRecordChange, "查询成功");
    }


}
